package com.spukmk3me.math;

public final class Vector3f
{
    public Vector3f() {}
    
    public Vector3f( float x, float y, float z )
    {
        set( x, y, z );
    }
    
    public void set( float x, float y, float z )
    {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    
    public void set( Vector3f vect )
    {
        x = vect.x;
        y = vect.y;
        z = vect.z;
    }
    
    public void mul( float t )
    {
        x *= t;
        y *= t;
        z *= t;
    }
    
    /**
     *  Multiply a matrix with this vector.
     *  \details
     *  [        ]   [x]
     *  [   M    ] x [y]
     *  [        ]   [z]
     *  [        ]   [1]
     *  @param m
     */
    public void mul( Matrix4f m )
    {
        float[] d = m.getRawData();
        float tX = d[ 0 ] * x + d[ 4 ] * y + d[ 8 ] * z + d[ 12 ];
        float tY = d[ 1 ] * x + d[ 5 ] * y + d[ 9 ] * z + d[ 13 ];
        float tZ = d[ 2 ] * x + d[ 6 ] * y + d[ 10 ] * z + d[ 14 ];
        
        x = tX;
        y = tY;
        z = tZ;
    }
    
    public void add( Vector3f vect )
    {
        x += vect.x;
        y += vect.y;
        z += vect.z;
    }
    
    public void dec( Vector3f vect )
    {
        x -= vect.x;
        y -= vect.y;
        z -= vect.z;
    }
    
    public float x, y ,z;
}
